<%@ page import="java.sql.*" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %><%--
  Created by IntelliJ IDEA.
  User: 自由如风
  Date: 2018/3/20
  Time: 16:19
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>

<head>
    <title>显示所有用户的信息</title>
    <style type="text/css">


        p {
            font-size: 8px;
        }

        a {
            font-size: 8px;
            color: blueviolet;
            text-decoration: underline;
        }


    </style>
</head>

<body>

<a href="userAdd.jsp">添加用户</a>
<a href="userSelect.jsp">用户查询</a>
<%
    Connection connection = null;
    Statement statement = null;

    try {
        Class.forName("com.mysql.cj.jdbc.Driver");

        connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sctu_javaweb_2018?serverTimezone = UTC", "root", "193749");
        statement = connection.createStatement();

        ResultSet resultSet = statement.executeQuery("SELECT * FROM t_users");

        out.print("<p>" + "编号" + "   用户名" + "   密码" + "</p>");
        while (resultSet.next()) {
            //按照页面格式进行输出
            out.print("<p>" + resultSet.getInt(1) + "           " + resultSet.getString(2) + "        " + resultSet.getString(3) + "   " +
                    "<a href='userUpdate.jsp?idvalue=" + resultSet.getInt(1) + "&namevalue=" + resultSet.getString(2) + "&passvalue=" + resultSet.getString(3) + "' >更新</a>" + "     " +
                    "<a href='userDelete.jsp?idvalue=" + resultSet.getInt(1) + "'>删除</a></p>");
        }

    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            statement.close();
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

%>

</body>
</html>